from query4disease import query_neo4j
from flask import Flask, url_for, request
import redis
import time
from PyCmpltrtok.common import md5, uuid
import os
from python_nlp.kg.neo4j.config import NEO4J_CONFIG_CBLUE
from neo4j import GraphDatabase

app = Flask(__name__)
rdb = redis.Redis(os.environ.get('REDIS_HOST', '127.0.0.1'), int(os.environ.get('REDIS_PORT', 6379)), 0)
driver = GraphDatabase.driver(**NEO4J_CONFIG_CBLUE)

@app.route("/seek", methods=['POST'])
def do_infer():
    req_json = request.get_json(force=True)  # 请求json
    xdesc = req_json['desc']

    xdis = query_neo4j(driver, xdesc, 0)
    
    res_json = dict()
    res_json['dis'] = xdis
    return res_json


if '__main__' == __name__:
    # 启动方式1： 启动命令
    # flask run --host=0.0.0.0 --port=7777

    # 启动方式2： 在这里启动
    # https://www.cnblogs.com/chaojiyingxiong/p/14988069.html
    app.run('0.0.0.0', 7777)
